<script type="text/javascript" src="../media/system/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../media/system/js/jQuery.vietvang.validate.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			$('#adminForm').validate({
			});
		});
</script>


<form action="index.php?option=com_questionare" method="post" class="adminform" id="adminForm" name="adminForm" enctype="multipart/form-data">
    <table class="tbl-ques" border=0>
    	<tr>
    		<td style="width: 20%;"><label>ID</label></td>
    		<td style="width: 40%;">
                <label><?php echo HelperBG::getIDAuto('serq','SERQ_CODE');?></label>
                <input name="jform[SERQ_CODE]" type="hidden"  value="<?php echo HelperBG::getIDAuto('serq','SERQ_CODE'); ?>" />
            </td>
    		<td style="width: 40%;"></td>
    	</tr>
    	<tr>
    		<td><label>アンケート名</label>	</td>
    		<td colspan="2">
                <input type="text" id="jform[SERQ_TITLE]" name="jform[SERQ_TITLE]" value="<?php echo $this->row->SERQ_TITLE; ?>" class="inputbox width" size="30" />
            </td>
    	</tr>
    	<tr>
    		<td>
                <label>説明</label>	
            </td>
    		<td colspan="2">
                <textarea cols="44" rows="6" id="jform[SERQ_DESCRIPTION]" name="jform[SERQ_DESCRIPTION]"><?php echo $this->row->SERQ_DESCRIPTION; ?></textarea>
             </td>
    	</tr>
        <tr>
            <td>画像</td>
            <td>
                <input type="file" id="jformSERQ_IMG" name="jformSERQ_IMG" class="big" size="30" onchange="onFileSelected(event)" />
            </td>
            <td> 
                <img class="img_questionare" id="jform[SERQ_IMG_OLD]" src="<?php if($this->row->SERQ_IMG != null) echo 'uploads/images/com_questionare/'. $this->row->SERQ_IMG ?>"  />
                <?php if(isset($this->row->SERQ_IMG)){ ?>
                        <input type="text" name="jformIMGD_OLD" value="<?php echo $this->row->SERQ_IMG; ?>" readonly="true" class="inputbox big readonly" />
                <?php }?>
            </td>
        </tr>
        <tr>
            <td><label>配信先</label></td>
            <td colspan="2">
                <input id="btnSERQ_SEND_USER_ID_LIST" name="btnSERQ_SEND_USER_ID_LIST"  type="button" value="配信先追加"/>
               
            </td>
        </tr>
        <tr>
            <td></td>
            <td colspan="2"><textarea id="jformMAIL_USER" name="jform[MAIL_USER]" cols="44" rows="6"  ><?php echo $this->row->SERQ_SEND_USER_ID_LIST; ?></textarea></td>
        </tr>
        <tr>
            <td><label>エンドページタイトル</label></td>
            <td colspan="2">
                <input type="text" name="jform[SERQ_END_TITLE]" value="<?php echo $this->row->SERQ_END_TITLE; ?>" class="inputbox width" size="30" />
            </td>
        </tr>
        <tr>
            <td><label>エンドページ説明</label></td>
            <td colspan="2">
                 <textarea cols="44" rows="4" id="jform[SERQ_END_DESCRIPTION]" name="jform[SERQ_END_DESCRIPTION]"><?php echo $this->row->SERQ_END_DESCRIPTION; ?></textarea>
            </td>
        </tr>
        <tr>
            <td><label>開始</label></td>
            <td>
                <?php if($this->row->SERQ_START != 0){ $dt = date('Y-m-d',strtotime($this->row->SERQ_START));}else{ $dt=null;} echo JHtml::calendar($dt, 'jform[SERQ_START]', 'jformSERQ_START');?>
                <span name="msg_error"></span> 
            </td>
            <td> 
            </td>
            
        </tr>
        <tr>
            <td><label>完了</label></td>
            <td colspan="2">
                <?php if($this->row->SERQ_FINISH != 0){ $dt = date('Y-m-d',strtotime($this->row->SERQ_FINISH));}else{ $dt=null;} echo JHtml::calendar($dt,  'jform[SERQ_FINISH]', 'jformSERQ_FINISH');?>
                <span name="msg_error"></span> 
            </td>
        </tr>
         <tr>
            <td><label>フロントページ</label></td>
            <td colspan="2">
                <select id="" id="jform[SERQ_PUBLISHED]" name="jform[SERQ_PUBLISHED]" class="width" >
                    <option value="1" <?php if($this->row->SERQ_PUBLISHED == '1') echo 'selected';?> >公開</option>
                    <option value="0" <?php if($this->row->SERQ_PUBLISHED == '0') echo 'selected';?>>非公開</option>
                </select>
            </td>
        </tr>
    </table>
  <div>
		<input type="hidden" name="task" value="">
		<input type="hidden" name="boxchecked" value="1">
		<input type="hidden" name="filter_order" value="a.title">
		<input type="hidden" name="filter_order_Dir" value="asc">
		<input type="hidden" name="6a31752ddc5d93062e73a249fa94a360" value="1">	</div>
</form>
<script>
    function onFileSelected(event) {
            var selectedFile = event.target.files[0];
                      var reader = new FileReader();
                    
                      var imgtag = document.getElementById("jform[SERQ_IMG_OLD]");
                      imgtag.title = selectedFile.name;
                    
                      reader.onload = function(event) {
                        imgtag.src = event.target.result;
                      };
                    
                      reader.readAsDataURL(selectedFile);   
    }
        
     window.addEvent('domready', function() {Calendar.setup({
        	// Id of the input field
        	inputField: "jformSERQ_START",
        	// Format of the input field
        	ifFormat: "%Y/%m/%d",
        	// Trigger for the calendar (button ID)
        	button: "jformSERQ_START",
        	// Alignment (defaults to "Bl")
        	align: "Bl",
        	singleClick: true,
        	firstDay: 0
    	});
    
    });
    
     window.addEvent('domready', function() {Calendar.setup({
        	// Id of the input field
        	inputField: "jformSERQ_FINISH",
        	// Format of the input field
        	ifFormat: "%Y/%m/%d",
        	// Trigger for the calendar (button ID)
        	button: "jformSERQ_FINISH",
        	// Alignment (defaults to "Bl")
        	align: "Bl",
        	singleClick: true,
        	firstDay: 0
    	});
    
    });
</script>
<script>
    jq(document).ready(function() {

        // show a dialog box when clicking on a link
        jq('#btnSERQ_SEND_USER_ID_LIST').bind('click', function(e) {
            e.preventDefault();
            jq.Zebra_Dialog('', {
                source:  {'ajax': 'index.php?option=com_questionare&view=bg&task=popup&tmpl=component'},
                /*source: {'iframe': {
                    
                    'src':  'index.php?option=com_popup&view=bg&task=popup&tmpl=component',
                    'height': 450
                }},*/
                height: 750,
                width: 850,
                title:  '送信先選択',
                type:  '',
                buttons:  [
                    {caption: 'キャンセル', callback: function() {}},
                    {caption: 'OK', callback: function() {
                        jq('#jformMAIL_USER').val(jq('#jformMAIL_USER').val()+jq('#list_uid').val());
                    }
                        
                    }
                ]
            });
        });   
                        
     });
</script>
